<style>
	.amap-wrapper {
		width: 900px;
		height: 600px;
	}
	
	.amap-demo {
		height: 100px;
	}
</style>
<template>
	<div>
		<Modal v-model="modalShow" :closable='false' :mask-closable=false fullscreen>
			<p slot="header">编辑车主</p>
			<Row>
				<Col span="16">
				<Form ref="formData" :model="formData" label-position="left" :label-width="100">
					
					

					<FormItem label="头像" prop="price">
						 <Avatar icon="ios-person" size="large" :src="formData.head_img"/>
					</FormItem>
					
					<FormItem label="车主姓名" prop="realname">
						<Input v-model="formData.realname" disabled/>
					</FormItem>
					
					<FormItem label="手机号" prop="username">
						<Input v-model="formData.username" disabled/>
					</FormItem>
					
					<FormItem label="昵称" prop="nickname">
						<Input v-model="formData.nickname" disabled/>
					</FormItem>
					
					<FormItem label="性别" prop="sex_text">
						<Input v-model="formData.sex_text" disabled/>
					</FormItem>
					
					<FormItem label="生日" prop="birthday">
						<Input v-model="formData.birthday" disabled/>
					</FormItem>


					<FormItem label="服务费率" prop="bonus">
						<Input v-model="formData.bonus">
						 <span slot="append">%</span>
						 </Input>
					</FormItem>
					
					<FormItem label="下属车辆" prop="num_car">
						<Input v-model="formData.num.car" disabled/>
					</FormItem>
					
					<FormItem label="下属网点" prop="num_dot">
						<Input v-model="formData.num.dot" disabled/>
					</FormItem>

				</Form>
				</Col>
			</Row>

			<div slot="footer">
				<Button type="text" @click="cancel">取消</Button>
				<Button type="primary" @click="edit" :loading='saveLoading'>保存 </Button>
			</div>
		</Modal>

	</div>
</template>
<script>
	import {
		getInfo,
		editCarUser,
	} from '@/api/caruser'

	//import Editor from '_c/editor'
	//import Upload from '_c/common/upload'
	export default {
		components: {
			//  Editor,
			//  Upload
		},
		props: {
			modalId: {
				type: Number,
				default: 0
			}
		},
		created() {
			let t = this;
			if(this.modalId > 0) {
				this.getInfoById()
			}
			//t.getSearchDataExcute();
		},
		data() {
			let t = this;
			return {
				modalShow: true,
				saveLoading: false,
				mapModal: false,
				mapModal1: false,
				getSearchData: {
					dot: [],
				},
				formData: {
					c_user_id:'',
					head_img: '',
					username: '',
					nickname: '',
					sex_text: '',
					birthday: '',
					bonus: '',
					num:{
						car:0,
						dot:0
					},
				}
			}
		},
		methods: {
			getInfoById() {
				let t = this
				getInfo(t.modalId).then(res => {
					//console.log(res);
					if(res.data.code == 1){
						let res_data = res.data.data;
						//console.log(res_data);
					    t.formData =  {
					    	c_user_id:res_data.car_user.c_user_id,
							head_img: res_data.car_user.head_img,
							realname:res_data.car_user.realname,
							username: res_data.car_user.username,
							nickname: res_data.car_user.nickname,
							sex_text: res_data.car_user.sex_text,
							birthday: res_data.car_user.birthday,
							bonus: res_data.car_user.p_bonus,
							num:{
								car:res_data.num.car+'辆',
								dot:res_data.num.dot+'个'
							}
						}
					   
					    
					
					}else{
						t.$Notice.error({
							title: res.data.msg
						})
						this.$emit('on-edit-modal-hide')
						this.modalShow = false
					}
					
				})

			},
//			getSearchDataExcute() {
//				let t = this;
//				getData().then(res => {
//					t.getSearchData.dot = res.data.data.dot;
//				}, function(error) {})
//			},
			edit() {
				let t = this
				t.$refs.formData.validate((valid) => {
					if(valid) {
						t.saveLoading = true
						
						let params ={
							c_user_id:t.formData.c_user_id,
							bonus:t.formData.bonus,
						}
						
						editCarUser(params).then(res => {
							if(res.data.code == 1) {
								t.saveLoading = false
								t.modalShow = false
								t.$emit('on-edit-modal-success')
								t.$emit('on-edit-modal-hide')
								t.$Notice.success({
									title: res.data.msg
								})
							} else {
								t.saveLoading = false
								t.$Notice.error({
									title: res.data.msg
								})
							}

						}, function(error) {
							t.saveLoading = false
						})
					}
				})
			},
			cancel() {
				this.$emit('on-edit-modal-hide')
				this.modalShow = false
			}
		},

	}
</script>